package com.h3c.ptability.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.h3c.ptability.dto.electronicSign.PtEsignSceneTemplateDTO;
import com.h3c.ptability.entity.PtEsignScene;
import com.h3c.ptability.mapper.PtEsignSceneTemplateMapper;
import com.h3c.ptability.entity.PtEsignSceneTemplate;
import com.h3c.ptability.service.IPtEsignSceneTemplateService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 电子签具体使用场景关联的虚签署的文件模板实现类
 *
 * @author chenyifan
 * @since 2022-05-19 11:01:34
 */
@Service
@AllArgsConstructor
public class PtEsignSceneTemplateServiceImpl extends ServiceImpl<PtEsignSceneTemplateMapper, PtEsignSceneTemplate> implements IPtEsignSceneTemplateService {

    private final PtEsignSceneTemplateMapper ptEsignSceneTemplateMapper;

    @Override
    public List<PtEsignSceneTemplate> selectEsignSceneTemplateByScene(List<PtEsignScene> esignSceneList) {
        List<String> sceneIds = esignSceneList.stream().map(PtEsignScene::getSceneId).collect(Collectors.toList());
        QueryWrapper<PtEsignSceneTemplate> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().in(PtEsignSceneTemplate::getSceneId, sceneIds);
        return list(queryWrapper);
    }

    @Override
    public List<PtEsignSceneTemplateDTO> getTemplateListBySceneId(String sceneId) {
        return ptEsignSceneTemplateMapper.selectTemplateDto(sceneId);
    }

    @Override
    public void deleteSceneTemplateBySceneId(String sceneId) {
        QueryWrapper<PtEsignSceneTemplate> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(PtEsignSceneTemplate::getSceneId, sceneId);
        remove(queryWrapper);
    }

}

